package com.mingzhi.alibaba.demo.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;

@RestController
@RequestMapping("/multi")
public class MultiModelController {

    private final ChatClient chatClient;

    public MultiModelController(ChatClient.Builder chatClient) {
        this.chatClient = chatClient.build();
    }

    @GetMapping("/image")
    public String image(String message) throws Exception {
        //拿到网络上图片的地址
        String imageUrl = "https://bpic.588ku.com/back_origin_min_pic/21/04/26/daec013230b6fd6401b1dd0654c52f29.jpg";

        Media media = new Media(MimeTypeUtils.IMAGE_JPEG, new URI(imageUrl).toURL().toURI());
        //定义用户的提示词
        UserMessage userMessage = UserMessage.builder()
                .text(message)
                .media(media)
                .build();

        //调用ai模型
        return chatClient.prompt(new Prompt(userMessage))
                .call()
                .content();
    }
}
